package cn.itsource.basic.domain;

import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.digest.MD5;

import java.util.Optional;

/**
 * 操作盐和密码的钩子工具类
 */
public interface CreatePassword {

    String getSalt();

    void setSalt(String salt);

    String getPassword();

    void setPassword(String password);

    //进来的this   =  admin  子类
    default void init() {
        //加密
        String salt = IdUtil.fastSimpleUUID();
        System.out.println(salt);
        String password = Optional.ofNullable(this.getPassword()).orElse("123");

        String md5Pwd = MD5.create().setSalt(salt.getBytes()).digestHex(password);
        this.setSalt(salt); //调用的都是子类的
        this.setPassword(md5Pwd);
    }



    //进来的this   =  admin  子类
    default String md5Password() {

        return MD5.create().setSalt(this.getSalt().getBytes()).digestHex(this.getPassword());

    }




}
